// pages/search/search.js
// 导入获取数据的方法
import { request } from '../../request/index.js'
import regeneratorRuntime, { async } from '../../lib/runtime/runtime';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        goods: [],
        isFocus: false,
        inpValue: ""
    },
    TimeId: 0,
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    handleInput(e) {
        const { value } = e.detail
        // 检测合法性
        if (!value.trim()) {
            this.setData({
                goods: [],
                isFocus: false
            })
            return
        }
        this.setData({
            isFocus: true

        })
        // 设置防抖
        clearTimeout(this.TimeId)
        this.TimeId = setTimeout(() => {
            this.qsearch(value)

        }, 1000);
    },
    // 发送请求
    async qsearch(query) {
        const res = await request({ url: '/goods/qsearch', data: { query } })
        this.setData({
            goods: res,

        })
    },
    // 点击取消
    handleCancel() {
        this.setData({
            goods: [],
            isFocus: false,
            inpValue: ""
        })
    }


})